package com.cdream.basic.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author cdream
 * @date 2022/2/13
 */
public class CasLock {
    private AtomicInteger lock = new AtomicInteger();
    public void lock(){
        while (true){
            if (lock.compareAndSet(0,1)){
                break;
            }
        }
    }
    public void  unlock(){
        lock.set(0);
    }
}
